package com.yxx.mapper;

import com.github.pagehelper.Page;
import com.yxx.annotation.AutoFill;
import com.yxx.medicinecommon.enumeration.OperationType;
import com.yxx.medicinepojo.dto.SetMedicinePageQueryDTO;
import com.yxx.medicinepojo.dto.SetmedicineDTO;
import com.yxx.medicinepojo.entity.SetMedicine;
import com.yxx.medicinepojo.vo.SetmedicineVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author yuxiangxun
 * @date 2024/9/7
 * @apiNote
 */
@Mapper
public interface SetMedicineMapper {

    /**
     * 根据分类id查询组合药的数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from setmedicine where medicine_category_id = #{categoryId}")
    Integer countByMedicineCategory_id(Long categoryId);

    /**
     * 多表查询，根据药品id查询组合药信息
     * select s.* from setmedicine s left join setmedicine_medicine sm on s.id = sm.setmedicine_id where sm.medicine_id = #{id}
     * @param id
     * @return
     */
    @Select("select s.* from setmedicine s left join setmedicine_medicine sm on s.id = sm.setmedicine_id where sm.medicine_id = #{id}")
    List<SetMedicine> getByChineseWesternMedicineById(Long id);

    /**
     * 根据 药品id 查询 组合药的id
     * @param Chinese_Western_Medicine_ids
     * @return
     */
    List<Long> setMedicineById(List<Long> Chinese_Western_Medicine_ids);

    /**
     * 组合药分页查询
     * @param setMedicinePageQueryDTO
     * @return
     */
    Page<SetmedicineVO> pageQuery(SetMedicinePageQueryDTO setMedicinePageQueryDTO);

    /**
     * 新增组合药
     * @param setMedicine
     */
    @AutoFill(value = OperationType.INSERT)
    void insertSetMedicine(SetMedicine setMedicine);

    /**
     * 根据id查询组合药信息
     * @param id
     * @return
     */
    @Select("select * from setmedicine where id = #{id}")
    SetMedicine getBySetmedicineId(Long id);

    /**
     * 通过药品id修改组合药信息
     * @param setMedicine
     */
    void updateSetMedicine(SetMedicine setMedicine);

    /**
     * 根据组合药id删除组合药品表信息
     * @param setmedicineId
     */
    @Delete("delete from setmedicine_medicine where setmedicine_id = #{setmedicineId};")
    void deleteBySetmedicineId(Long setmedicineId);

    /**
     * 批量删除组合药信息（组合药表）
     * @param ids
     */
    void deleteByIds(List<Long> ids);

    /**
     * 根据map（上/下架和分类id）条件统计组合药数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    /**
     * 条件查询组合药信息
     * @param setMedicine
     * @return
     */
    List<SetMedicine> list(SetMedicine setMedicine);
}
